package com.example.thread.d9CompletableFuture2.d9大数据商品比价;

import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.util.StringJoiner;
import java.util.concurrent.TimeUnit;

public class CommonUtilsPlus {

    public static String readFile(String pathToFile) {
        try {
            return pathToFile;
        } catch (Exception e){
            e.printStackTrace();
            return "";
        }
    }
    public static void sleepMillis(long millis) {
        try {
            TimeUnit.MICROSECONDS.sleep(millis);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    public static void sleepSecond(int seconds) {
        try {
            TimeUnit.SECONDS.sleep(seconds);
        }catch (Exception e) {
            e.printStackTrace();
        }
    }

    private static String getCurrentTime() {
        LocalTime now = LocalTime.now();
        return now.format(DateTimeFormatter.ofPattern("[HH:mm:ss.SSS]"));
    }

    public static void printThreadLog(String message) {
        String result = new StringJoiner(" | ")
                .add(getCurrentTime())
                .add(String.format("%2d",Thread.currentThread().getId()))
                .add(Thread.currentThread().getName())
                .add(message)
                .toString();
        System.out.println(result);
    }

}
